package com.dehui.traders.app;

import android.content.Context;
import android.content.pm.PackageManager;

import com.dehui.traders.R;
import com.dehui.traders.config.Preferences;
import com.mob.MobSDK;

import cn.jpush.android.api.JPushInterface;
import me.goldze.mvvmhabit.base.BaseApplication;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;

/**
 * Created by hqq on 18.3.29.
 */

public class AppApplication extends BaseApplication {

    private static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        init();
    }

    public static Context getContext() {
        return mContext;
    }

    private void init() {
        Preferences.setContext(this);

        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("fonts/msyh.ttf")
                .setFontAttrId(R.attr.fontPath)
                .build()
        );

        MobSDK.init(this);

        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
    }

    public static int getVersionCode() {
        int versionCode = 0;
        try {
            versionCode = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    public static String getVersionName() {
        String versionName = "1.0.0";
        try {
            versionName = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionName;
    }

}
